package com.lhy.admin.common.mvcplus.controller;

import com.lhy.admin.common.mvcplus.entity.ReqCriteria;
import com.lhy.admin.common.mvcplus.entity.RespPage;
import com.lhy.admin.common.mvcplus.entity.RespResult;
import com.lhy.admin.common.mvcplus.entity.SearchCriteria;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;
import java.util.Set;

public interface SimpleQueryController<T extends Serializable, P extends Serializable> {

    /**
     * countCriteria
     * 条件计数
     * @param searchCriteria searchCriteria
     * @return {@link RespResult<Long>}
     * @author hyluan
     * @date 2022/6/27 17:17
     */
    @RequestMapping(value = "count", method = RequestMethod.POST)
    @Operation(summary =  "条件计数", description =  "条件计数，自定义字段，字段值，和条件，支持复杂查询")
    RespResult<Long> countCriteria(@Validated @RequestBody SearchCriteria searchCriteria);

    /**
     * searchCriteria
     * 条件分页查询，自定义字段，字段值，和条件，支持复杂查询
     * @param criteriaReq criteriaReq
     * @return {@link RespResult< RespPage<T>>}
     * @author hyluan
     * @date 2022/6/27 17:17
     */
    @RequestMapping(value = "search", method = RequestMethod.POST)
    @Operation(summary =  "条件分页查询", description =  "条件分页查询，自定义字段，字段值，和条件，支持复杂查询")
    RespResult<RespPage<T>> searchCriteria(@Validated @RequestBody ReqCriteria criteriaReq);

    /**
     * 按多个条件查询<br/>
     * 请求路径 /path/list?id=<br/>
     * get方法<br/>
     * 参数注解: @Validated @ModelAttribute
     * @param bean
     * @return RespResult<List<T>>
     * @throws
     * @date 2018/8/17 16:17
     */
    @RequestMapping(value = "list", method = RequestMethod.GET)
    @Operation(summary =  "按多个条件查询", description =  "按多个条件查询")
    RespResult<List<T>> queryCond(@Validated @ModelAttribute T bean);

    /**
     * listByIds 按多个id查询
     *
     * @param items items
     * @return {@link RespResult< List<T>>}
     * @author hyluan
     * @date 2022/10/11 18:06
     */
    @RequestMapping(value = "listByIds", method = RequestMethod.GET)
    @Operation(summary =  "按多个id查询", description =  "按多个id查询")
    RespResult<List<T>> listByIds(@RequestParam("items") Set<P> items);
}
